<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户授权</title>
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/icon.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<%
	String para = request.getParameter("f_po_id");
	int f_po_id = 0;
	if(para != null)
		f_po_id = Integer.valueOf(para);
String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
	var f_po_id = <%=f_po_id%>;
	$(function(){
		$("#authorizeList").empty();
		//获取组织名称
		$.ajax({
			url:"org_select.do?f_po_id="+f_po_id,
			success:function(data) {
				data=JSON.parse(data);
				$("#f_po_name").html(data.f_po_name);
			}
		});
		//获取组织关联角色列表
		$.ajax({
			url:"roleOrg_select.do?f_po_id="+f_po_id,
			success:function(data) {
				data=JSON.parse(data);
				var str="<td></td>";
				for(var i=0;i<data.length;i++){
					str+="<td>"+data[i].f_prole_name+"</td>";
				}
				var roleStr ="<tr>"+str+"</tr>";
				$("#authorizeList").append(roleStr);
				//获取组织关联用户列表
				var userStr="";
				$.ajax({
					url:"orgUser_select.do?f_po_id="+f_po_id,
					success:function(userData) {
						userData = JSON.parse(userData);
						for(var j=0;j<userData.length;j++) {
							var lineStr="<td>"+userData[j].f_pu_name+"</td>";
							for(var k=0;k<data.length;k++) {
								lineStr+="<td><input id='"+userData[j].f_pu_id+""+data[k].f_prole_id+"' type='checkbox' value='"+userData[j].f_pu_id+","+data[k].f_prole_id+"'/></td>";
							}
							userStr+="<tr>"+lineStr+"</tr>"
						}
						$("#authorizeList").append(userStr);
						//查询组织用户角色关联表
						$.ajax({
							url:"orgUserRole_select.do?f_po_id="+f_po_id,
							success:function(orgUserRoleData) {
								orgUserRoleData=JSON.parse(orgUserRoleData);
								for(var num=0;num<orgUserRoleData.length;num++) {
									var id=orgUserRoleData[num].f_pour_userId+""+orgUserRoleData[num].f_pour_roleId;
									$("#"+id).attr("checked","true");
								}
							}
						});
					}
				});
			}
		});
	});
	
	function _submitFm() {
		//获取选中的值
		var userRoleList = "";
		$(":checkbox").each(function(){
			if(this.checked==true) {
				userRoleList+=this.value+";";
			}
		});
		//提交
		$.ajax({
			url:"orgUserRole_add.do",
			data:"f_po_id="+f_po_id+"&userRightValue="+userRoleList,
			success:function(data) {
				data = JSON.parse(data);
				if (data.success) {
					$.messager.progress('close');
					$.messager.alert('提示', '授权成功！', 'info', function() {
						parent.$('#dlg').dialog('close');
						parent.gotoSearch($('#easyui-treegrid'));
					});
				} else {
					$.messager.alert('提示', data.result, 'info', function() {
						$.messager.progress('close');
					});
				}
			}
		});
	}
</script>
</head>

<body class="overfwidth">
	<div class="barnavtop">您所在的位置：用户管理 &gt; 用户授权</div>
	<div id="workspace">
		<!--主体 开始-->
		<div id="container">
			<div class="editspace">
				<form id="contentForm" class="cmxform" enctype="multipart/form-data"
					name="formName">
					<legend>用户授权</legend>
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="left">组织名称：</td>
									<td width="70%" id="f_po_name"></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table id="authorizeList" width="100%" border="0" cellpadding="0"
								cellspacing="0">

							</table>
						</div>
					</fieldset>
					<input type="hidden" name="stime" value="<%=nonceObj[0]%>"/>
					<input type="hidden" name="sign" value="<%=nonceObj[1]%>"/>
				</form>
			</div>
			<div class="toolbar" style="text-align: center;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
					href="javascript:void(0);" onclick="_submitFm()">保存</a> <a
					href="javascript:void(0);" data-options="iconCls:'icon-cancel'"
					class="easyui-linkbutton"
					onclick="javascript:parent.$('#dlg').dialog('close')">取消</a>
			</div>
		</div>
		<!--主体 结束-->
	</div>
</html>
